package com.e5.training.action;

import org.springframework.beans.factory.annotation.Autowired;

import com.e5.training.domain.User;
import com.e5.training.service.UserService;
import com.opensymphony.xwork2.ActionContext;

public class SignUpAction {
	@Autowired
	private UserService userService;
	private String firstname;
	private String lastname;
	private String address1;
	private String address2;
	private String city;
	private String province;
	private String post;
	private String country;
	private String Authority;
	private String title;
	private String userid;
	private String password;
	private String repassword;

	public String getFirstname() {
		return firstname;
	}

	public void setFirstname(String firstname) {
		this.firstname = firstname;
	}

	public String getLastname() {
		return lastname;
	}

	public void setLastname(String lastname) {
		this.lastname = lastname;
	}

	public String getAddress1() {
		return address1;
	}

	public void setAddress1(String address1) {
		this.address1 = address1;
	}

	public String getAddress2() {
		return address2;
	}

	public void setAddress2(String address2) {
		this.address2 = address2;
	}

	public String getCity() {
		return city;
	}

	public void setCity(String city) {
		this.city = city;
	}

	public String getProvince() {
		return province;
	}

	public void setProvince(String province) {
		this.province = province;
	}

	public String getPost() {
		return post;
	}

	public void setPost(String post) {
		this.post = post;
	}

	public String getCountry() {
		return country;
	}

	public void setCountry(String country) {
		this.country = country;
	}

	public String getAuthority() {
		return Authority;
	}

	public void setAuthority(String authority) {
		Authority = authority;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getUserid() {
		return userid;
	}

	public void setUserid(String userid) {
		this.userid = userid;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getRepassword() {
		return repassword;
	}

	public void setRepassword(String repassword) {
		this.repassword = repassword;
	}

	public String execute() {
		String returnStr = "error";
		try {
			User user = new User();
			user.setAddr1(this.getAddress1());
			user.setAddr2(this.getAddress2());
			user.setCity(this.getCity());
			user.setCountry(this.getCountry());
			user.setFirstName(this.getFirstname());
			user.setLastName(this.getLastname());
			user.setPassword(this.getPassword());
			user.setState(this.getProvince());
			user.setZip(this.getPost());
			user.setTitle(this.getTitle());
 			user.setUserAuth(Integer.parseInt(this.getAuthority()));
			user.setUserID(this.getUserid());
			
			if (userService.signup(user)) {
//				ActionContext.getContext().getSession()
//				.put("accountInfo", user);
				returnStr = "success";
			} else {
				returnStr = "error";
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return returnStr;
		}
		return returnStr;
	}

}
